<?
class Cal{
	var $year;
	var $month;
	var $days;
	var $today;
	var $startDays;
	var $upToDate;
	var $nextMonth;
	var $preMonth;
	var $nm;
	var $pm;
	var $nextYear;
	var $preYear;
	var $ny;
	var $py;
	var $mouseR;
	var $id = array(42);
	var $d;
	var $no;
	var $width;
	var $height;
	var $bgColor;
	var $borderColor;


	function Cal($url,$idOfDiv,$year,$month){
		if($month>=12){
			$month =12;
		}

		if(!$this->month){
			$this->month = date("n");
		}
		if(!$this->year){
			$this->year = date("Y");
		}
		$this->today =date("j");

		if($year){
			$this->year=$year;
		}
		if($month){
			$this->month=$month;
		}
		$this->nextMonth=$this->month + 1;
		$this->preMonth=$this->month - 1;
		$this->nm="<a onClick=\"calControl('$url?month=$this->nextMonth&year=$this->year','$idOfDiv');\"> > </a>";
		$this->pm="<a onClick=\"calControl('$url?month=$this->preMonth&year=$this->year','$idOfDiv');\"> < </a>";
		$this->nextYear=$this->year + 1;
		$this->preYear=$this->year - 1;
		$this->ny="<a onClick=\"calControl('$url?month=$this->month&year=$this->nextYear','$idOfDiv');\"> >> </a>";
		$this->py="<a onClick=\"calControl('$url?month=$this->month&year=$this->preYear','$idOfDiv');\"> << </a>";
		$this->mouseR="onMouseOver=\"this.style.backgroundColor='#d0cacd'\" onMouseOut=\"this.style.backgroundColor='' \"";
		$this->startDays = date("w" , mktime(0,0,0,$this->month,1,$this->year));
		$this->upToDate = date("t", mktime(0,0,0,$this->month,1,$this->year));
		for($this->d=$this->startDays + 1,$this->days=1;$this->days<=$this->upToDate;$this->d++,$this->days++) {
			$this->id[$this->d] = $this->days ;
		}
		$this->width=300;
		$this->height=300;
		$this->color="white";
		$this->borderColor = "gray";
	}

	function setSize($w,$h){
		$this->width=$w;
		$this->height=$h;
	}

	function setBgColor($c){
		$this->bgColor=$c;
	}

	function setBorderColor($c){
		$this->borderColor=$c;
	}

	function showCal(){
		$top="
		<table align='center' width='$this->width' height='$this->height' bgcolor='$this->bgColor'>
		<tr>
		<td colspan='7'>
		<center>
		$this->py $this->pm $this->year 년 $this->month 월 $this->nm $this->ny
					</center>
				</td>
			</tr>
			<tr>
				<td><font color=red>일</font></td>
				<td>월</td>
				<td>화</td>
				<td>수</td>
				<td>목</td>
				<td>금</td>
				<td><font color=blue>토</font></td>
			</tr>
		";
		echo $top;
		$w="";
		for($tr=0;$tr<=5;$tr++) {
			echo"<tr>";
			for($td=1;$td<=7;$td++) {
				$this->no = $td + ($tr*7) ;

				if($this->no%7==0){
					$w="토요일";
				}
				if($this->no%7==1){
					$w="일요일";
				}
				if($this->no%7==2){
					$w="월요일";
				}
				if($this->no%7==3){
					$w="화요일";
				}
				if($this->no%7==4){
					$w="수요일";
				}
				if($this->no%7==5){
					$w="목요일";
				}
				if($this->no%7==6){
					$w="금요일";
				}
				//mktime(시, 분, 초, 월, 일, 년);

				$click="onClick=\"setDate('$this->year','$this->month','".$this->id[$this->no]."','$w','".mktime(1,1,1,$this->month,$this->id[$this->no],$this->year)."');\" ";

				if(($this->id[$this->no]==$this->today)&&($this->month==date("n"))&&($this->year==date("Y"))){
					echo"<td  bgcolor=yellow style=\"border:2px solid green;\" $this->mouseR $click>".$this->id[$this->no]."</td>";
				}
				elseif($this->no%7==1){
					echo"<td  style=\"border:1px solid $this->borderColor; \" $this->mouseR $click><font color=red>".$this->id[$this->no]."</font></td>";
				}
				elseif($this->no%7==0){
					echo"<td style=\"border:1px solid $this->borderColor;\" $this->mouseR $click><font color=blue>".$this->id[$this->no]."</font></td>";
				}
				else{echo"<td style=\"border:1px solid $this->borderColor;\" $this->mouseR $click>".$this->id[$this->no]." </td>";
				}
			}
			echo"</tr>";
		}
		$bottom="
				<tr>
				<td colspan='7'></td>
			</tr>
		</table>
			";
		echo $bottom;
	}
}
?>






